package com.zhhs.galaxyott.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

import android.annotation.SuppressLint;
import android.text.TextUtils;

public class DateUtils {

    public static final String YYYYMMDD = "yyyy-MM-dd";
    public static final String YYYYMMDD_HHMMSS = "yyyy-MM-dd HH:mm:ss";
    public static final String MMDD_HHMM = "MM月dd日 HH:mm";
    public static final String YYYYMMDD_HHMM = "yyyy.MM.dd HH:mm";
    public static final String HHMMSS = "HH:mm:ss";

    /**
     * 将date转换成string
     */
    public static String dateToStringFormat(Date date, String params) {
        SimpleDateFormat format = new SimpleDateFormat(params);
        return format.format(date);
    }

    /**
     * 将date转换成string：年月日、 时分秒
     */
    public static String dateToStringFormat_YH(Date date) {
        SimpleDateFormat format = new SimpleDateFormat(YYYYMMDD_HHMMSS);
        return format.format(date);
    }

    /**
     * 将date转换成string：月日、 时分
     */
    public static String dateToStringFormat_MH(Date date) {
        SimpleDateFormat format = new SimpleDateFormat(MMDD_HHMM);
        return format.format(date);
    }

    /**
     * 把long时间转换成 mm-dd
     * 
     * @param time
     *            long时间
     */
    @SuppressLint("SimpleDateFormat")
    public static String getLongDate_MH(String time) {
        String retime = null;
        try {
            if (time.length() != 0) {
                SimpleDateFormat sdf = new SimpleDateFormat(MMDD_HHMM);
                long longTime = Long.valueOf(time);
                retime = sdf.format(new Date(longTime));
            } else {
                retime = "未知";
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return retime;
    }

    /**
     * 把long时间转换成 yyyy-mm-dd
     * 
     * @param time
     *            long时间
     */
    @SuppressLint("SimpleDateFormat")
    public static String getLongDate_YH(String time) {
        String retime = null;
        try {
            if (time.length() != 0) {
                SimpleDateFormat sdf = new SimpleDateFormat(YYYYMMDD_HHMM);
                long longTime = Long.valueOf(time);
                retime = sdf.format(new Date(longTime));
            } else {
                retime = "未知";
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return retime;
    }

    /**
     * 
     * TODO:输入一个时间，获取该时间的时间戳
     * 
     * @param @param dateString
     * @param @return
     * @param @throws ParseException
     */
    public static long string2Timestamp_YH(String dateString) {
        if (dateString == null) {
            return 0;
        }
        try {
            Date date1 = new SimpleDateFormat(YYYYMMDD_HHMMSS).parse(dateString);
            long temp = date1.getTime();// JAVA的时间戳长度是13位
            return temp;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    public static long string2Timestamp_Y(String dateString) {
        if (dateString == null) {
            return 0;
        }
        try {
            Date date1 = new SimpleDateFormat(YYYYMMDD).parse(dateString);
            long temp = date1.getTime();// JAVA的时间戳长度是13位
            return temp;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    public static long string2Timestamp_H(String dateString) {
        if (dateString == null) {
            return 0;
        }
        try {
            Date date1 = new SimpleDateFormat(HHMMSS).parse(dateString);
            long temp = date1.getTime();// JAVA的时间戳长度是13位
            return temp;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    /**
     * 日期
     * 
     * @param data
     * @return
     */
    public static String getMMDDData(String data) {
        String time = null;
        if (TextUtils.isEmpty(data)) {
            return time;
        }
        String[] str = data.split(" ");
        if (str.length > 0) {
            String[] hsm = str[0].split("-");
            time = hsm[1] + "-" + hsm[2];
        }
        return time;
    }

}
